package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Packsack;
import cn.wolfcode.trip.base.mapper.PacksackMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IPacksackService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PacksackServiceImpl implements IPacksackService {
    @Autowired
    private PacksackMapper packsackMapper;
    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<Packsack> orderLists = packsackMapper.selectForList(qo);
        return new PageInfo(orderLists);
    }

    @Override
    public void save(Packsack packsack) {
        if (packsack.getId() != null) {
            packsackMapper.updateByPrimaryKey(packsack);
        }else {
            packsackMapper.insert(packsack);
        }
    }

    @Override
    public void saveSign(Packsack packsack) {
        if (packsack != null) {
            packsack.setGaintime(new Date());
            packsack.setIsget(Packsack.ISGET_NO);
            packsackMapper.insert(packsack);
        }
    }
}
